/*
 * Class created by lensfrex.
 */

package net.lensfrex.dscape.domain.response;

//@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> {
    private final int code;
    private final String message;
    private final T data;

    public Response(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Response{");
        sb.append("code=").append(code);
        sb.append(", message='").append(message).append('\'');
        sb.append(", data=").append(data);
        sb.append('}');
        return sb.toString();
    }

    public static<T> Response<T> success(T data) {
        return new Response<>(20000, "success", data);
    }

    public static Response<Object> error(int code, String message) {
        return new Response<>(code, message, null);
    }
}
